package cn.baizhi.service.impl;

import cn.baizhi.entity.Admin;
import cn.baizhi.mapper.AdminMapper;
import cn.baizhi.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LZM
 * @since 2021-11-24
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Map<String, Object> login(String username,String password) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);

        Map<String, Object> map = new HashMap<>();
        Admin admin1 = adminMapper.selectOne(queryWrapper);

        if(admin1 != null){
            if(admin1.getPassword().equals(password)){
                map.put("msg","登录成功");
                map.put("state","success");
            }else{
                map.put("msg","密码错误");
                map.put("state",false);
            }

        }else{
            map.put("msg","用户名不存在");
            map.put("state",false);
        }
        return map;
    }
}
